﻿#include <iostream>
#include <future>
#include <thread>       // 引入线程库，用于创建线程
int heavy_computation() {
    std::cout << "Computing..." << std::endl;
    std::this_thread::sleep_for(std::chrono::seconds(2));
    return 42;
}

int main() {
    auto fut = std::async(std::launch::deferred, heavy_computation);
    std::cout << "Doing other things...\n";

    std::cout << "Now need the result...\n";
    std::cout << "Result: " << fut.get() << std::endl;  // 此时才开始执行函数
}
